<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table cellspacing="0" border="0" width="995">
	<tr>
		<td width="995" class="title_manager_product">Quản lý tin tức</td>
	</tr>
	<tr>
		<td>
			<table border="0" cellpadding="0" cellspacing="0" width="995">
				<tr>
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><a href="index.php?admin=newAdmin&do=formaddnews"><img src="images/CreateNews.gif" width="48" height="47" border="0" /></a></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=newAdmin&do=formaddnews">Thêm tin tức</a></td>
							</tr>
						</table>
						
					</td>
					
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><a href="index.php?admin=newAdmin&do=formaddnewtype"><img src="images/CreateCategory.gif" width="51" height="48" border="0" /></a></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=newAdmin&do=formaddnewtype">Thêm kiểu tin tức</a></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>	
	</tr>
</table>
<table cellspacing="0" border="0" width="995">
	<tr>
		<td width="200" valign="top">					
			<?php
				include("menuleftnew.php");
			?>
		</td>	
		<td width="790" valign="top">
			<table cellspacing="0" border="0" width="790">
				<tr>
				
				</tr>
			</table>
			
			<table cellspacing="0" cellpadding="0" border="0" width="790">
				<tr>
					<td>
						<form action="index.php?admin=newAdmin&do=formaddnews" method="post" enctype="multipart/form-data">
							<table cellspacing="0" border="0" width="790">
								<tr>
									<td width="995" class="title_manager_cate">Thêm tin tức</td>
								</tr>
							</table>
					    	<table class="reference" cellspacing="0" border="1" width="790">
					    		<tr>
					    			<td></td>
					    			<td>
					    				<?php
											$newName=$_POST['newName'];
											
											$newDetail=$_POST['newDetail'];
											
											$newID=$_POST['newID'];
											$state=$_POST['state'];
											
											$newContent=$_POST['newContent'];
											
											$target="../user/upload/news/";
											
											$link = $target.$_FILES['newImage']['name'];
											//$today = date("d-M-Y");
											move_uploaded_file($_FILES['newImage']['tmp_name'],$link);
											
											if(isset($_POST['submit'])){
												if(empty($newName)){
													echo "<font color=\"red\">Bạn phải nhập vào tiêu đề tin.</font>";
												}
												if(empty($newDetail)){
													echo "<font color=\"red\">Bạn phải nhập vào mô tả tin.</font>";
												}
												
												if($newName!='' && $newDetail!=''){
													$query="INSERT INTO newdetails(newName,newDetail,newImage,newContent,datecreated,newID,state) VALUES ('$newName','$newDetail','$link','$newContent',now(),'$newID','$state')";
													mysql_query($query);
													echo "Thêm tin tức thành công.";
													echo "<script>window.location='index.php?admin=newAdmin&do=listnew'</script>";
												}
											}
										?>	
					    			</td>
					    		</tr>
					        	<tr>
					            	<td width="205" align="right"><b>Tiêu đề tin:</b></td>
					                <td width="700"><input type="text" name="newName" size="30" maxlength="250" /><font color="#ff0000"> * </font></td>
					            </tr>
					             <tr>
					            	<td align="right"><b>Mô tả tin:</b></td>
					                <td>
					                	<input type="text" name="newDetail" size="50" /><font color="#ff0000"> * </font>
					                </td>
					            </tr>
					            <tr>
					            	<td align="right"><b>Loại tin:</b></td>
					                <td>
					                	<select name="newID">
					                		<?php					
					                    	$query = "select * from news";
											$result=mysql_query($query);
											while($row=mysql_fetch_array($result)){?>
												<option value="<?php echo $row['id']?>"><?php echo $row['titleNew'];?></option>	
											<?php
					                        }
											?>
					                     </select>   
					                </td>
					            </tr>
					            <tr>
					            	<td align="right"><b>Trạng thái tin:</b></td>
					                <td>
					                	<select name="state">
					                    	<option value="on">Hiện tin</option>
					                        <option value="off">Ẩn tin</option>
					                    </select>
					                </td>
					            </tr>
					            <tr>
					                <td align="right"><b>Tin ảnh:</b></td>
					                <td>
					                    <input type="file" name="newImage" />
					                </td>
					            </tr>
					            <tr>
					                <td align="right"><b>Nội dung tin:</b></td>
					                <td>
					                	<textarea name="newContent" size="32" rows="20" /></textarea>
					                </td>
					            </tr>
					            <tr>
					            	<td></td>
					                <td>
					                	<input type="submit" name="submit" value="Đăng tin" />
					                	<input type="reset" name="reset" value="Nhập lại" />
					                	<input type="button" name="Cancel" value="Cancel" onclick="window.location = 'index.php?admin=newAdmin&do=listnew' " />     
					                </td>
					            </tr>
					        </table>
					    </form>
					</td>
				</tr>				
			</table>
		</td>
	</tr>	
</table>
</body>
</html>